#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    vector<int> getSubarrayBeauty(vector<int>& nums, int k, int x) {
        int n = nums.size();
        vector<int> ret(n - k + 1);
        vector<int> cur(101);
        for (int i = 0; i < k - 1; i++)
            cur[nums[i] + 50]++;

        auto tgt = [&]()->int
            {
                int count = x;
                int i = 0;
                for (; i < 51; i++)
                {
                    count -= cur[i];
                    if (count <= 0) break;
                }
                int tgt = i - 50;
                return tgt < 0 ? tgt : 0;
            };

        for (int i = 0; i < n - k + 1; i++)
        {
            cur[nums[i + k - 1] + 50]++;
            ret[i] = tgt();
            cur[nums[i] + 50]--;
        }
        return ret;
    }
};